package com.mango.Tools;


public class TestTools {
    static class Ponit {
        private double x;
        private double y;
        private String lable;

        public Ponit(double x, double y, String lable) {
            this.x = x;
            this.y = y;
            this.lable = lable;
        }

        public Ponit() {
        }

        public double getX() {
            return x;
        }

        public void setX(double x) {
            this.x = x;
        }

        public double getY() {
            return y;
        }

        public void setY(double y) {
            this.y = y;
        }

        public String getLable() {
            return lable;
        }

        public void setLable(String lable) {
            this.lable = lable;
        }

        @Override
        public String toString() {
            return "Ponit{" +
                    "x=" + x +
                    ", y=" + y +
                    ", lable='" + lable + '\'' +
                    '}';
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj) return true;
            if (obj == null || getClass() != obj.getClass()) return false;
            Ponit other = (Ponit) obj;
            double equalX = this.x - other.getX();
            double equalY = this.y - other.getY();
            boolean equalLable = false;
            if (this.lable == null && other.getLable() == null) equalLable = true;
            else if (this.lable != null && other.getLable() != null) {
                equalLable = this.lable.equals(other.getLable());
            } else
                equalLable = false;

            if (equalX == 0 && equalY == 0 && equalLable) return true;
            else return false;

        }

        @Override
        public int hashCode() {
            int result = lable.hashCode();
            result = 31 * result + (int) x + (int) y;
            return result;
        }
    }

    public static void main(String[] args) throws Exception {
        Ponit p1 = new Ponit();
        p1.setX(1.02);
        p1.setY(23.04);
        p1.setLable("test");

        Ponit p2 = new Ponit();
        p2.setX(1.02);
        p2.setY(23.04);
        p2.setLable("test");
        System.out.println(p1 == p2);
    }

}